// 封装category面包屑导航相关的业务代码
import {getCategoryAPI} from "@/api/category"
import { onMounted, ref} from "vue"
import {useRoute,onBeforeRouteUpdate} from "vue-router"
export function useCategory(){
    const CategoryData = ref({})
    const route = useRoute()
    const getCategory =async (id = route.params.id)=>{
      const res = await getCategoryAPI(id)
      // console.log('一级详情页下的res',res)
      CategoryData.value = (res as any).result
      // console.log('CategoryData--------',CategoryData)
    }
    onMounted(()=>getCategory())
    
    onBeforeRouteUpdate((to)=>{
    console.log('to',to)
    getCategory(to.params.id)
    })
    return {
        CategoryData
      
}
}